@extends('admin.layout')

@section('title', '后台管理中心')

@section('body')
    <div class="layui-layout layui-layout-admin">
        <div class="layui-header">
            <div class="layui-logo">
                <i class="layui-icon layui-icon-app"></i>
                后台管理中心
            </div>
            <ul class="layui-nav layui-layout-right">
                <li class="layui-nav-item">
                    <a href="javascript:;">
                        <img src="{{ $avatar }}" class="layui-nav-img"/>
                        {{ $username }}
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="/admin/password" target="frame">修改密码</a></dd>
                        <dd><a href="/admin/logout">注销登录</a></dd>
                    </dl>
                </li>
            </ul>
        </div>

        <div class="layui-side">
            <div class="layui-side-scroll">
                <ul class="layui-nav layui-nav-tree">
                    <li class="layui-nav-item layui-nav-itemed">
                        <a class="" href="javascript:;">
                            <i class="layui-icon layui-icon-home"></i>
                            <cite>控制面板</cite>
                        </a>
                        <dl class="layui-nav-child">
                            <dd class="layui-this"><a href="/admin/main" target="frame">信息统计</a></dd>
                            <dd><a href="{{ config('app.url') }}" target="_blank">网站首页</a></dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item layui-nav-itemed">
                        <a class="" href="javascript:;">
                            <i class="layui-icon layui-icon-template"></i>
                            <cite>文章管理</cite>
                        </a>
                        <dl class="layui-nav-child">
                            <dd><a href="/admin/article/add" target="frame">发布文章</a></dd>
                            <dd><a href="/admin/article" target="frame">管理文章</a></dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item layui-nav-itemed">
                        <a href="javascript:;">
                            <i class="layui-icon layui-icon-tabs"></i>
                            <cite>分类管理</cite>
                        </a>
                        <dl class="layui-nav-child layui-nav-itemed">
                            <dd><a href="/admin/category/add" target="frame">添加分类</a></dd>
                            <dd><a href="/admin/category" target="frame">管理分类</a></dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item layui-nav-itemed">
                        <a href="javascript:;">
                            <i class="layui-icon layui-icon-dialogue"></i>
                            <cite>评论管理</cite>
                        </a>
                        <dl class="layui-nav-child">
                            <dd>
                                <a href="/admin/comment" target="frame">
                                    评论列表
                                    @if ($newComment)
                                        <span class="layui-badge-dot"></span>
                                    @endif
                                </a>
                            </dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item layui-nav-itemed">
                        <a href="javascript:;">
                            <i class="layui-icon layui-icon-link"></i>
                            <cite>友情链接</cite>
                        </a>
                        <dl class="layui-nav-child layui-nav-itemed">
                            <dd><a href="/admin/link/add" target="frame">添加添加</a></dd>
                            <dd><a href="/admin/link" target="frame">管理链接</a></dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item layui-nav-itemed">
                        <a href="javascript:;">
                            <i class="layui-icon layui-icon-set-sm"></i>
                            <cite>系统设置</cite>
                        </a>
                        <dl class="layui-nav-child">
                            <dd><a href="/admin/setting" target="frame">参数设置</a></dd>
                            <dd><a href="/admin/password" target="frame">修改密码</a></dd>
                        </dl>
                    </li>
                </ul>
            </div>
        </div>

        <div class="site-tree-mobile layui-hide layui-icon layui-icon-spread-left"></div>
        <div class="site-mobile-shade"></div>

        <div class="layui-body">
            <iframe src="/admin/main" frameborder="0" name="frame" class="iframe-box"></iframe>
        </div>
    </div>

    <script>
        layui.use(['element', 'layer'], function () {
            var $ = layui.$;
            var layer = layui.layer;

            //当文章编辑页的编辑器最大化时，隐藏头部、侧边栏
            window.onEditorMaximize = function (flag) {
                if (flag == 1) {
                    $('.layui-layout-admin').addClass('editor-maxsize');
                } else {
                    $('.layui-layout-admin').removeClass('editor-maxsize');
                }
            }

            $('.site-tree-mobile').on('click', function () {
                $('body').addClass('site-mobile');
            });

            $('.site-mobile-shade').on('click', function () {
                $('body').removeClass('site-mobile');
            });

            $('.layui-nav-child a[target=frame]').click(function () {
                layer.load(1);
                $('.site-mobile-shade').click();
                $(this).find('.layui-badge-dot').hide();

                setTimeout(function (targetPathname) {
                    var currentPathname = $('.iframe-box')[0].contentWindow.location.pathname;
                    if (currentPathname != targetPathname) {
                        setSelectClass(currentPathname);
                        layer.closeAll();
                    }
                }, 100, $(this).attr('href'));
            });

            $('.iframe-box').load(function () {
                var currentPathname = $(this)[0].contentWindow.location.pathname;
                setSelectClass(currentPathname);
                layer.closeAll();
            });

            function setSelectClass(pathname) {
                $('.layui-side a[target=frame]').each(function () {
                    if ($(this).attr('href') === pathname) {
                        $('.layui-this').removeClass('layui-this');
                        $(this).parent().addClass('layui-this');
                        return false;
                    }
                });
            }
        });
    </script>
@endsection
